<template>
  <div class="item-config">
        <el-button
            type="primary"
            style="width:165px;"
            size="small"
            @click="startAuth"
            >{{ $t('custom.connector.syncAuthorization') }}</el-button>
  </div>
</template>

<script>
import { Component } from './modules/Component.js'
import Trail from '@/components/storybook/mixins/trail'

export default {
  mixins: [Trail],

  props: {
    qbonlineConfigForm: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data () {
    return {
      testLoading: false
    }
  },
  methods: {
    startAuth () {
      let authId = 'AB8cYXfEhn6nz2OY0Xt5E1Mqv2jKrr9HLyUvybRLQjAIuz1E9P'
      let url = window.location.origin
      const quickbookAuthURL = 'https://appcenter.intuit.com/app/connect/oauth2' +
          '?client_id=' + authId +
          '&scope=com.intuit.quickbooks.accounting openid profile email phone address' +
          '&redirect_uri=' + url + '/web/task-management/quickbookonline/redirect' +
          '&response_type=code' +
          '&state=' + this.$store.state.user.tenantCode + '_' + this.$store.state.user.id
      window.open(quickbookAuthURL, '_blank')
    },
    validateConfigForm () {
      return this.$refs['quick-books-online-form'].validate()
    },
    synctdData (itemInfo) {
      const params = {
        tenantId: this.$store.state.user.tenantCode,
        subjectCode: 'QUICKBOOKSONLINE'
      }
      this.$interface.taskManager.syncClientData(params).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        if (itemInfo && res.data && res.data.sync) {
          itemInfo.sync.lastTime = res.data.sync.lastTime
          itemInfo.sync.status = res.data.sync.status
        }
        Component.$emit('getConnectorConfig')
        return this.$message.success(res.msg)
      }).catch(() => {
      })
    }
  }
}
</script>

<style scoped></style>
